var express = require('express');
var router = express.Router();
let { journeyModel, progressModel } = require('../db/model')
router.post('/addjourney', (req, res) => {
    let obj = req.body
    console.log(obj);
    journeyModel.create(obj)
    res.send({
        code: 200
    })

})
router.get("/getjourney", async (req, res) => {
    let { userid, _id } = req.query
    console.log(userid, _id);

    if (_id) {
        let data = await journeyModel.find({ _id })
        res.send({
            code: 200,
            data
        })
    } else {
        let data = await journeyModel.find({ userid })
        res.send({
            code: 200,
            data
        })
    }

})

router.post('/uploadImg', (req, res) => {
    let form = new multiparty.Form()
    form.uploadDir = "upload"
    form.parse(req, (err, a, imgData) => {
        res.send({
            code: 200,
            path: "http://localhost:3000/" + imgData.file[0].path,
        })
    })
})


router.post('/addprogress', (req, res) => {
    let obj = req.body
    console.log(obj);
    progressModel.create(obj)
    res.send({
        code: 200
    })

})
router.get("/getprogress",async(req,res)=>{
    let data = await progressModel.find().populate('jid')
    let journey = await journeyModel.find()
    res.send({
        code:200,
        data
    })
})
module.exports = router;
